const Router = require('koa-router');
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");
router.post('/app/delBill', async ctx => {
    let tenantId= ctx.user.tenantId
    let body= ctx.request.body
    let billId = body.billId
    let invoice = await db.models['invoice'].findOne({
        where: {
            tenantId,
            id: billId
        }
    })
    if(!invoice) return ctx.err('未发现票据')
    if(invoice.billState !== 'draft') return ctx.err('不能删除此票据')
    await invoice.destroy()
    return ctx.suc('已删除')
})


module.exports = router;